<!DOCTYPE html>
<html>
<head>
    <title>商品列表</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link type="text/css" rel="stylesheet" href="../css/bootstrap.css">
    <link type="text/css" rel="stylesheet" href="../css/style.css">
    <script type="text/javascript" src="../../js/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="../js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../layer/layer.js"></script>
    <script type="text/javascript" src="../js/cart.js"></script>
    <script type="text/javascript" src="../js/auth.js"></script>
    <script type="text/javascript" src="../js/CookieShop.js"></script>
</head>
<body>
<!--header-->
<div class="header">
    <div class="container">
        <nav class="navbar navbar-default" role="navigation">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <h1 class="navbar-brand"><a href="./index"></a></h1>
            </div>
            <!--navbar-header-->
            <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                    <li><a href="./index.html" class="active">首页</a></li>
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">商品分类<b class="caret"></b></a>
                        <ul class="dropdown-menu multi-column columns-2">
                            <li>
                                <div class="row">
                                    <div class="col-sm-12">
                                        <h4>商品分类</h4>
                                        <ul class="multi-column-dropdown" id="goodsTypeMenu">
                                            <li><a class="list" href="./goods_list.html">全部系列</a></li>
                                        </ul>
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </li>
                    <li><a href="./goodsrecommend_list.html?recommendTypeId=2" id="hotListMenu">热销</a></li>
                    <li><a href="./goodsrecommend_list.html?recommendTypeId=3" id="newListMenu">新品</a></li>
                </ul>
                <!--/.navbar-collapse-->
            </div>
            <!--//navbar-header-->
        </nav>
        <div class="header-info">
            <div class="header-right search-box">
                <a href="javascript:;"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></a>
                <div class="search">
                    <form class="navbar-form" action="./goods_search.html">
                        <input type="text" class="form-control" name="keyword">
                        <button type="submit" class="btn btn-default" aria-label="Left Align">搜索</button>
                    </form>
                </div>
            </div>

            <div class="header-right cart">
                <a href="./goods_cart.html">
                    <span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"><span class="card_num">0</span></span>
                </a>
            </div>
            <div class="clearfix"> </div>
        </div>
        <div class="clearfix"> </div>
    </div>
</div>
<!--banner-->
<div class="banner">
    <div class="container">
        <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
            <!-- Indicators -->
            <ol class="carousel-indicators" id="olnum">
            </ol>

            <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox" id="lunbotu" style="width: 1242px; height: 432px;">
            </div>
        </div>
    </div>
</div>
<!--//banner-->
<div class="subscribe2"></div>
<!--gallery-->
<div class="gallery">
    <div class="container">
        <div class="alert alert-danger">热销推荐</div>
        <div class="gallery-grids" id="hotList">
        </div>
        <div class="clearfix"></div>
        <div class="alert alert-info">新品推荐</div>
        <div class="gallery-grids" id="newList">
        </div>
    </div>
</div>
<!--//gallery-->
<!--subscribe-->
<div class="subscribe"></div>
<!--//subscribe-->
<!--footer-->
<div class="footer">
    <div class="container">
        <div class="text-center">

        </div>
    </div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function(){
countMyCart();
genGoodsTypesMenu();
decorateMainMenu();
loadData();
});

function loadData(){
	$.ajax({
		type:"post",
		url: "../custcontroller/indexCustController/index",
		dataType: 'json',
		success: function(data, textStatus) {
			debugger;
			if ( data.scroll !=null ){
			   for (let i=0;i<data.scroll.length;i++){
				  appendScrollRow(data.scroll[i],i);
				}
			   for (let i=0;i<data.scroll.length;i++){
				  appendScrollRow2(data.scroll[i],i);
				}
			}
			if ( data.hotList !=null ){
			   for (let i=0;i<data.hotList.length;i++){
				  appendHotGoodsRow(data.hotList[i],i);
				}
			}
			if ( data.newList !=null ){
			   for (let i=0;i<data.newList.length;i++){
				  appendNewGoodsRow(data.newList[i],i);
				}
			}
		},
		complete : function(XMLHttpRequest, textStatus) {
		},
		error : function(XMLHttpRequest,textStatus,errorThrown) {
			alert("Error:"+textStatus);
			alert(errorThrown.toString());
		}
	});
}

function appendScrollRow(row,index){
  var rowStr = "";
  if (index == 0) {
    rowStr += "<li data-target=\"#carousel-example-generic\" data-slide-to=\"0\" class=\"active\"></li>\n";
  }else {
    rowStr += "<li data-target=\"#carousel-example-generic\" data-slide-to=\""+index+"\"></li>\n";
  }
  $("#olnum").append(rowStr);
}

function appendScrollRow2(row,index){
  var rowStr = "";
  if (index == 0) {
    rowStr += "<div class=\"item active\">\n"+
              "<h2 class=\"hdng\"><a href=\"./goods_detail.html?id="+row.id+"\">"+row.name+"</a><span></span></h2>\n"+
              "<p>今日精选推荐</p>\n"+
              "<a class=\"banner_a\" href=\"javascript:;\" onclick=\"buy("+row.id+",1)\">立刻购买</a>\n"+
              "<div class=\"banner-text\">\n"+
              "<a href=\"./goods_detail.html?id="+row.id+"\">\n"+
              "<img src=\"data:image/png;base64,"+row.cover+"\" alt=\""+row.name+"\" width=\"350\" height=\"350\">\n"+
              "</a>\n"+
              "</div>\n"+
              "</div>\n";
  }else {
    rowStr += "<div class=\"item\">\n"+
              "<h2 class=\"hdng\"><a href=\"./goods_detail.html?id="+row.id+"\">"+row.name+"</a><span></span></h2>\n"+
              "<p>今日精选推荐</p>\n"+
              "<a class=\"banner_a\" href=\"javascript:;\" onclick=\"buy("+row.id+",1)\">立刻购买</a>\n"+
              "<div class=\"banner-text\">\n"+
              "<a href=\"./goods_detail.html?id="+row.id+"\">\n"+
              "<img src=\"data:image/png;base64,"+row.cover+"\" alt=\""+row.name+"\" width=\"350\" height=\"350\">\n"+
              "</a>\n"+
              "</div>\n"+
              "</div>\n";
  }
  $("#lunbotu").append(rowStr);
}

function appendHotGoodsRow(row,index){
  var rowStr = "<div class=\"col-md-4 gallery-grid glry-two\">\n"+
              "<a href=\"./goods_detail.html?id="+row.id+"\">\n"+
              "<img src=\"data:image/png;base64,"+row.cover+"\"  class=\"img-responsive\" alt=\""+row.name+"\" width=\"350\" height=\"350\"/>\n"+
              "</a>\n"+
              "<div class=\"gallery-info galrr-info-two\">\n"+
              "<p>\n"+
              "<span class=\"glyphicon glyphicon-eye-open\" aria-hidden=\"true\"></span>\n"+
              "<a href=\"./goods_detail.html?id="+row.id+"\">查看详情</a>\n"+
              "</p>\n"+
              "<a class=\"shop\" href=\"javascript:;\" onclick=\"buy("+row.id+")\">立刻购买</a>\n"+
              "<div class=\"clearfix\"></div>\n"+
              "</div>\n"+
              "<div class=\"galy-info\">\n"+
              "<p>"+row.goodsTypeId+">"+row.name+"</p>\n"+
              "<div class=\"galry\">\n"+
              "<div class=\"prices\">\n"+
              "<h5 class=\"item_price\">¥ "+row.price+"</h5>\n"+
              "</div>\n"+
              "<div class=\"clearfix\"></div>\n"+
              "</div>\n"+
              "</div>\n"+
              "</div>\n";
    $("#hotList").append(rowStr);
}

function appendNewGoodsRow(row,index){
  var rowStr = "<div class=\"col-md-3 gallery-grid \">\n"+
                "<a href=\"./goods_detail.html?id="+row.id+"\">\n"+
                "<img src=\"data:image/png;base64,"+row.cover+"\" class=\"img-responsive\" alt=\""+row.name+"\"/>\n"+
                "</a>\n"+
                "<div class=\"gallery-info\">\n"+
                "<p>\n"+
                "<span class=\"glyphicon glyphicon-eye-open\" aria-hidden=\"true\"></span>\n"+
                "<a href=\"./goods_detail.html?id="+row.id+"\">查看详情</a>\n"+
                "</p>\n"+
                "<a class=\"shop\" href=\"javascript:;\" onclick=\"buy("+row.id+")\">立刻购买</a>\n"+
                "<div class=\"clearfix\"></div>\n"+
                "</div>\n"+
                "<div class=\"galy-info\">\n"+
                "<p>"+row.goodsTypeId+" > "+row.name+"</p>\n"+
                "<div class=\"galry\">\n"+
                "<div class=\"prices\">\n"+
                "<h5 class=\"item_price\">¥ "+row.price+"</h5>\n"+
                "</div>\n"+
                "<div class=\"clearfix\"></div>\n"+
                "</div>\n"+
                "</div>\n"+
                "</div>\n";
   $("#newList").append(rowStr);
}

function showCoverImage(row){
	if(row.cover){
		return "<img style='height:100px;' border='1' src='data:image/png;base64,"+row.cover+"'/>";
	} else {
		return "<img style='height:100px;' border='1' src='../../images/blank.jpg'/>";
	}
}

function genOperationTd(row){
	var tdStr =	"<td>\n"+
				"<p>\n";
	if (row.isScroll) {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=remove&typeTarget=1&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">移出条幅</a>";
	} else {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=add&typeTarget=1&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">加入条幅</a>";
	}
	if (row.isHot) {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=remove&typeTarget=2&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">移出热销</a>";
	} else {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=add&typeTarget=2&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">加入热销</a>";
	}
	if (row.isNew) {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=remove&typeTarget=3&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">移出新品</a>";
	} else {
	 tdStr += "<a class=\"btn btn-info\" href=\"/admin/goods_recommend?id="+row.id+"&method=add&typeTarget=3&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">加入新品</a>";
	}
	tdStr += "</p>\n"+
				"<a class=\"btn btn-success\" href=\"/admin/goods_editshow?id="+row.id+"&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">修改</a>\n"+
				"<a class=\"btn btn-danger\" href=\"/admin/goods_delete?id="+row.id+"&pageNumber="+row.pageNumber+"&goodsTypeId="+row.goodsTypeId+"\">删除</a>\n"+
				"</td>\n";
	return tdStr;
}
</script>
</html>
